<?php
    include('session.inc');
    require_once('funct.inc');
    include 'color_style.php';
    include '../definitions.inc.php';
    include LANGUAGE;
    if(!GetAdminID($ID)){echo LOGIN_ERR;exit;}
    if(!Right_Check(1)){header('Location:error.php');exit;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<?php echo '<meta http-equiv="Content-Type" content="image/jpeg; charset='._CHARSET_.';">'; ?>

<?php include 'html_style.php';

/*	<!-- tinyMCE -->
	<script language="javascript" type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
	<script language="javascript" type="text/javascript">
		// Notice: The simple theme does not use all options some of them are limited to the advanced theme
		tinyMCE.init({
			mode : "textareas",
			theme : "simple"
			
		});
	</script>
	<!-- /tinyMCE -->*/
?>
</head>
<?php
print "<body bgcolor=".Background_Color.">";



require_once('OpenDB.inc');
require_once('functs.inc');

do
{
if (!OpenDB()){echo OPEN_DB_ERR; break;}


$Category_ID=$_REQUEST["ID"];
$Path=$_REQUEST["path"];
$show_new_product=0;
$events=$_REQUEST["events"];

$ChBox[1]="checked";

$Product_Code=$_REQUEST["Product_Code"];
$Product_Name=$_REQUEST["Product_Name"];
$Product_Price=$_REQUEST["Product_Price"];
$Product_Descr=$_REQUEST["Product_Descr"];
if($_REQUEST["inStack"]=="2/")$ChBox[1]="checked";else$ChBox[1]="";
if($_REQUEST["action"]=="1/")$ChBox[0]="checked";
//$UnitType=$_REQUEST["UnitType"];

if($Product_Code=="" and
   $Product_Name=="" and
   $Product_Price=="" and
   $Product_Descr=="")
   {$ChBox[1]="checked";}

    switch($events) {
    case 'add_product':
                            if (!is_numeric($_REQUEST["Product_Price"]) and $_REQUEST["Product_Price"]!=""){
                                 print  "<script language=\"JavaScript\">
                                            <!--
                                            window.alert(\"".C_NESPRAVNA_HODNOTA_CENY_ZADAJTE_CISLO_SO_SPRAVNYM_ODDELOVACOM_DES_MIEST.": ' ".$_REQUEST["Product_Price"]." '\");
                                            //-->
                                         </script>";
                            break;
                            }
                            if(($_FILES['ImagePicker']['tmp_name'])!=""){
                                  if(!in_array($_FILES['ImagePicker']['type'],array('image/jpeg' , 'image/pjpeg' ))){
                                  print  "<script language=\"JavaScript\">
                                                  <!--
                                                  window.alert(\"".C_OBRAZOK_NIE_JE_TYPU_JPG.": '".$_FILES['ImagePicker']['name']."'\");
                                                  //-->
                                               </script>";
                                  break;
                                  }
                            }
                            if($_REQUEST["Product_Name"]==""){
                            print  "<script language=\"JavaScript\">
                                            <!--
                                            window.alert(\"".C_NEZADALI_STE_NAZOV_TOVARU."\");
                                            //-->
                                         </script>";
                            break;
                            }
                            if($_REQUEST["Product_Price"]==""){
                            print  "<script language=\"JavaScript\">
                                            <!--
                                            window.alert(\"".C_NEZADALI_STE_CENU_TOVARU."\");
                                            //-->
                                         </script>";
                            break;
                            }
                            if($_FILES['ImagePicker']['size']>MAX_IMAGE_SIZE){
                            print  "<script language=\"JavaScript\">
                                            <!--
                                            window.alert(\"".C_OBRAZOK_1_JE_PRILIZ_VELKY.": ".MAX_IMAGE_SIZE." KB.\");
                                            //-->
                                         </script>";
                            break;
                            }
                            if($_FILES['ImagePicker2']['size']>MAX_IMAGE_SIZE){
                            print  "<script language=\"JavaScript\">
                                            <!--
                                            window.alert(\"".C_OBRAZOK_2_JE_PRILIZ_VELKY.": ".MAX_IMAGE_SIZE." KB.\");
                                            //-->
                                         </script>";
                            break;
                            }
                            if($_FILES['ImagePicker3']['size']>MAX_IMAGE_SIZE){
                            print  "<script language=\"JavaScript\">
                                            <!--
                                            window.alert(\"".C_OBRAZOK_3_JE_PRILIZ_VELKY.": ".MAX_IMAGE_SIZE." KB.\");
                                            //-->
                                         </script>";
                            break;
                            }
                            $New_ID=add_SQL(
                            $_REQUEST["Product_Code"],
                            $_REQUEST["Product_Name"],
                            $_REQUEST["Product_Price"],
                            $_REQUEST["Product_Descr"],
                            $_REQUEST["inStack"],
                            $_REQUEST["action"],
                            $_REQUEST["UnitType"],
                            $Category_ID,
                            $_FILES['ImagePicker']['tmp_name'],
                            $_FILES['ImagePicker2']['tmp_name'],
                            $_FILES['ImagePicker3']['tmp_name'],
							$_REQUEST["Product_DPH"]);
                            $show_new_product=1;
                            
                            //-------------------------------------------------------------------
							//modul shared_products - funkcie defiovane hore
							if(file_exists("modules/shared_products/shared_products.inc")){
								require_once("modules/shared_products/shared_products.inc");
								Save_Shared_Products_From_Cookie_To_DB($New_ID);
            				}
                            
                            //************************modul tables********************************
							//**************************************************************************
							//**************************************************************************
							if(file_exists("modules/tables/insert_7.inc"))  
							{
							  include('modules/tables/insert_7.inc');
                            }
							//**************************************************************************
							//**************************************************************************
							//************************************************************************** 
                             break;

           default:break;
                    }
                    
  print"<BR>";
 print("<center><b>".$Path."</b></center>");
 if($Category_ID==""){mysql_close(); break;}
 //PrintLine();

 print "<hr width=98% align=left style=\"border-top:1px solid black; margin-bottom=0; margin-top=0;
           position:relative;left:0px; top:10px;\">";

if(!$show_new_product){
        //shared products button
        if(file_exists("modules/shared_products/shared_products.inc")){
            require_once("modules/shared_products/shared_products.inc");
            $shared_products = '
                <input type="button" alt="'.SP_SUVISIACE_PRODUKTY.'" value="'.SP_SUVISIACE_PRODUKTY.'"
                    style="border:1px solid black; width :160px; background-color: '.BUTTON_ON_OUT.';"
                    onmouseover="this.style.backgroundColor=\''.BUTTON_ON_OVER.'\'; this.style.fontWeight=\'bold\';"
                    onmouseout="this.style.backgroundColor=\''.BUTTON_ON_OUT.'\'; this.style.fontWeight=\'normal\';"
                    onClick="javascript:window.open(\'modules/shared_products/adm_main_frame.php?ProductID=0\',\'shared_products\',\'width=1000px,height=600px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes\');"
                />
            ';
         }
         //default hidden elements
         $hidden_elements ='
            <input type="hidden" name="events" id="events" value="add_product" />
            <input type="hidden" name="path" value="'.$Path.'" />
            <input type="hidden" name="ID" value="'.$Category_ID.'" />
            <input type="hidden" name="MAX_FILE_SIZE" value="550000" />
         ';
         //save button
         $save_button = '
            <input type="submit" value="'.C_ULOZ.'"
                style="width :160px; background-color: '.BUTTON_ON_OUT.';"
                onmouseover="this.style.backgroundColor=\''.BUTTON_ON_OVER.'\'; this.style.fontWeight=\'bold\';"
                onmouseout="this.style.backgroundColor=\''.BUTTON_ON_OUT.'\'; this.style.fontWeight=\'normal\';"
            />
        ';
        //cancel button
        $cancel_button = '
            <input type="button" value="'.C_NASPAT.'"
                style="width :160px; background-color: '.BUTTON_ON_OUT.';"
                onmouseover="this.style.backgroundColor=\''.BUTTON_ON_OVER.'\'; this.style.fontWeight=\'bold\';"
                onmouseout="this.style.backgroundColor=\''.BUTTON_ON_OUT.'\'; this.style.fontWeight=\'normal\';"
                onClick="javascript:window.open(\'adm_contents.php?ID='.$Category_ID.'&path='.$Path.'\',\'contents\', \'\');"
            />
        ';
        //insert form
        $insert_form = '
            <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                <tr>
                    <td>
                        <b>'.C_NAZOV.':</b> <input type="text" name="Product_Name" id="Product_Name" size="35" maxlength="50" value="" />
                        <b>'.C_KOD.':</b> <input type="text" name="Product_Code" id="Product_Code" size="20" maxlength="20" value="" />
                    </td>
                </tr>
                <tr>
                    <td style="padding-top:10px;">
                        <b>'.C_POPIS.':</b><br>
                        <textarea name="Product_Descr" rows="8" wrap="on" style="width:390px;"></textarea>
                    </td>
                </tr>
                <tr>
                    <td style="padding-top:10px;">
                        <b>'.C_DPH.':</b> <input type="text" name="Product_DPH" id="Product_DPH" maxlength="2" size="5" value="'.sttngs_DEFAULT_VAT.'" />
                        %
                        <b>'.C_CENA.':</b> <input type="text" name="Product_Price" id="Product_Price" size="12" value="'.FormatItAsCurrencyTEXTEDIT(0).'" />
                        '.C_MENA.' /
                        <input type="text" name="UnitType" id="UnitType" maxlength="5" size="5" value="" />
                    </td>
                </tr>
                <tr>
                    <td style="padding-top:10px;">
                        <input type="checkbox" value="1/" name="action" />
                        <font color="red" ><small><b>'.C_AKCIA_POPIS.'</b></small></font>
                        <input type="checkbox" value="2/" name="inStack" />
                        <font color="black" ><small>'.C_TOVAR_NA_SKLADE.'</small></font>
                    </td>
                </tr>

            </table>
        ';
        //images list
        $images_list = '
            <tr>
                <td>
                    <center><b>'.C_OBRAZKY.':</b></center>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="file" accept=".jpg" size="14" name="ImagePicker" title="'.C_VYBER_OBRAZKU.'" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="file" accept=".jpg" size="14" name="ImagePicker2" title="'.C_VYBER_OBRAZKU.'" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="file" accept=".jpg" size="14" name="ImagePicker3" title="'.C_VYBER_OBRAZKU.'" />
                </td>
            </tr>
        ';

        //table
        print '
            <form name="formular" action="adm_new_product.php" target="contents" method="post"  enctype="multipart/form-data">
            '.$hidden_elements.'
            <table  border="0" cellpadding="3" cellspacing="3" width="780px" bgcolor="'.$bgcolor.'">
                <tr>
                    <td style="width:190px; text-align:left; vertical-align:top; border-right: 1px dotted black;"> <!-- Images -->
                        <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                            '.$images_list.'
                        </table>
                    </td>
                    <td style="width:410px; text-align:left; vertical-align:top; border-right: 1px dotted black;"> <!-- Products info -->
                        '.$insert_form.'
                    </td>
                    <td style="width:160px; text-align:right; vertical-align:top;"> <!-- Controls -->
                        <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                            <tr>
                                <td>
                                    '.$shared_products.'
                                </td>
                            </tr>
                            <tr>
                                <td style="padding-top:10px;">
                                    '.$save_button.'
                            </tr>
                            <tr>
                                <td>
                                    '.$cancel_button.'
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            </form>
        ';
         print "<hr width=98% align=left style=\"border-top:1px solid black; margin-bottom=0; margin-top=0;
           position:relative;left:0px; top:0px;\">";
}
else{
    $sql_psel="SELECT * FROM products WHERE ID=".$New_ID;
    $Product_source = mysql_query($sql_psel);
    $sql_array_Prodct = mysql_fetch_object($Product_source);

    $actionProduct=Is_Action($sql_array_Prodct->ID);
    $productInStack=Is_in_stack($sql_array_Prodct->ID);
    $Product_Name=$sql_array_Prodct->Product_Name;
    $Product_Descr=$sql_array_Prodct->Product_Descr;
    $Product_Code=$sql_array_Prodct->Product_Code;
    $Product_Price=$sql_array_Prodct->Product_Price;
    $Product_DPH=$sql_array_Prodct->Product_DPH;
    $Product_UnitType=$sql_array_Prodct->Product_UnitType;




            if ($actionProduct) $ChBox[0]="checked"; else $ChBox[0]="";
            if ($productInStack)$ChBox[1]="checked"; else $ChBox[1]="";

            //otvorenie formulara na show podrobnosti
            if($counter%2) $bgcolor = TR_BACKGOUND_COLOR_2; else $bgcolor = TR_BACKGOUND_COLOR_1;

            //next insert button
            $next_insert_button = '
                <form action="adm_new_product.php" target="contents" method="post">
                    <input type="hidden" name="path" value="'.$Path.'">
                    <input type="hidden" name="ID" value="'.$Category_ID.'">
                    <input type="submit" value="'.C_DALEJ.'" style="width :160px; background-color: '.BUTTON_ON_OUT.';"
                        onmouseover="this.style.backgroundColor=\''.BTN_IN_TABLE.'\'; this.style.fontWeight=\'bold\';"
                        onmouseout="this.style.backgroundColor=\''.BUTTON_ON_OUT.'\'; this.style.fontWeight=\'normal\';"
                    />
                </form>
            ';
            //cancel button
            $cancel_button = '
                <input type="button" value="'.C_NASPAT.'"
                    style="width :160px; background-color: '.BUTTON_ON_OUT.';"
                    onmouseover="this.style.backgroundColor=\''.BUTTON_ON_OVER.'\'; this.style.fontWeight=\'bold\';"
                    onmouseout="this.style.backgroundColor=\''.BUTTON_ON_OUT.'\'; this.style.fontWeight=\'normal\';"
                    onClick="javascript:window.open(\'adm_contents.php?ID='.$Category_ID.'&path='.$Path.'\',\'contents\', \'\');"
                />
            ';
            //product form
            $product_form = '
                <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                    <tr>
                        <td>
                            <b>'.C_NAZOV.':</b> '.$Product_Name.'
                            <br />
                            <b>'.C_KOD.':</b> '.$Product_Code.'
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-top:10px;">
                            <b>'.C_POPIS.':</b>
                            <br>
                            '.$Product_Descr.'
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-top:10px;">
                            <b>'.C_DPH.': '.$Product_DPH.'
                            %
                            <b>'.C_CENA.':</b> '.FormatItAsCurrencyTEXTEDIT($Product_Price).'
                            '.C_MENA.' / '.$Product_UnitType.'
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-top:10px;">
                            <input type="checkbox" value="1/" name="action" DISABLED '.$ChBox[0].' />
                            <font color="red" ><small><b>'.C_AKCIA_POPIS.'</b></small></font>
                            <input type="checkbox" value="2/" name="inStack" DISABLED '.$ChBox[1].' />
                            <font color="black" ><small>'.C_TOVAR_NA_SKLADE.'</small></font>
                        </td>
                    </tr>

                </table>
            ';
            //images list
            $image_name  ="../data/images/".$sql_array_Prodct->ID."mini.jpg";
            $image_name2 ="../data/images/".$sql_array_Prodct->ID."d2mini.jpg";
            $image_name3 ="../data/images/".$sql_array_Prodct->ID."d3mini.jpg";
            $images_list = '
                <tr>
                    <td>
                        <center><b>'.C_OBRAZKY.':</b></center>
                    </td>
                </tr>
            ';
            if(file_exists($image_name)) $images_list .= "
                <tr>
                    <td width=\"90px\">
                        <img
                            style=\"cursor:hand;\"
                            src=\"".$image_name."?n=".rand(0, 2000)."\" align=\"left\" vspace=\"0px\" style=\"margin:5px;width : 70px;\"
                            onClick=\"javascript:window.open('image_show.php?image_name_big=../data/images/".$sql_array_Prodct->ID.".jpg','Image','width=680px,height=500px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes');\"
                        />
                    </td>
                </tr>";

            if(file_exists($image_name2)) $images_list .= "
                <tr>
                    <td width=\"90px\">
                        <img
                            style=\"cursor:hand;\"
                            src=\"".$image_name2."?n=".rand(0, 2000)."\" align=\"left\" vspace=\"0px\" style=\"margin:5px;width : 70px;\"
                            onClick=\"javascript:window.open('image_show.php?image_name_big=../data/images/".$sql_array_Prodct->ID."d2.jpg','Image','width=680px,height=500px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes');\"
                        />
                    </td>
                </tr>";

            if(file_exists($image_name3)) $images_list .= "
                <tr>
                    <td width=\"90px\">
                        <img
                            style=\"cursor:hand;\"
                            src=\"".$image_name3."?n=".rand(0, 2000)."\" align=\"left\" vspace=\"0px\" style=\"margin:5px;width : 70px;\"
                            onClick=\"javascript:window.open('image_show.php?image_name_big=../data/images/".$sql_array_Prodct->ID."d3.jpg','Image','width=680px,height=500px,location=no,directories=no,menubar=no,resizeable=yes,status=no,toolbar=no,scrollbars=yes');\"
                        />
                    </td>
                </tr>";

            //table
            print '
                <table  border="0" cellpadding="3" cellspacing="3" width="780px" bgcolor="'.$bgcolor.'">
                    <tr>
                        <td style="width:190px; text-align:left; vertical-align:top; border-right: 1px dotted black;"> <!-- Images -->
                            <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                                '.$images_list.'
                            </table>
                        </td>
                        <td style="width:410px; text-align:left; vertical-align:top; border-right: 1px dotted black;"> <!-- Products info -->
                            <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                                <tr>
                                    <td>
                                        '.$product_form.'
                                    </td>
                                </tr>
                                <tr>
                                    <td style="padding-top:10px;">
                                        '.Show_Shared_Products_After_Insert_New_Product($sql_array_Prodct->ID).'
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td style="width:160px; text-align:right; vertical-align:top;"> <!-- Controls -->
                            <table  border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="'.$bgcolor.'">
                                <tr>
                                    <td>
                                        '.$next_insert_button.'
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        '.$cancel_button.'
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            ';
            Unset_Shared_Products_Session();
            PrintLine();
}

 //PrintLine();
  mysql_close();
}
while(false)
?>

</body>

</html>